package com.ryl.yomall.mq.controller;

import com.ryl.yomall.model.common.result.Result;
import com.ryl.yomall.mq.config.DeadLetterMqConfig;
import com.ryl.yomall.mq.config.DelayMQConfig;
import com.ryl.yomall.rabbitmq.service.RabbitService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Date 15:01
 * @Author ryl
 */
@RestController
@RequestMapping("/api/mq")

public class MQSendController {
    @Autowired
    private RabbitService rabbitService;
    //发路由模式
    @GetMapping("/sendMessage")
    public Result sendMessage(String message){
        rabbitService.sendMessage ( "exchange123","routingKey123",message );
        return Result.ok ();
    }
    //基于死信
    @GetMapping("/sendDeadLetterMessage")
    public Result sendDeadLetterMessage(String message,int delayTime){
        rabbitService.sendDeadLetterMessage ( DeadLetterMqConfig.exchange_dead,
                DeadLetterMqConfig.routing_dead_1,message,delayTime);
        return Result.ok ();
    }
    //基于延迟插件
    @GetMapping("/sendDelayMessage")
    public Result sendDelayMessage(String message,int delayTime){
        rabbitService.sendDelayMessage ( DelayMQConfig.exchange_delay,
                DelayMQConfig.routing_delay,message,delayTime);
        return Result.ok ();
    }
}
